﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Order_Management
{
 class Order:IComparable<Order>
    {
        public Order(int id, OrderDetails oD)
        {
            this.orderId = id;
            this.orderDetails = oD;
        }

        private int orderId;
        public OrderDetails orderDetails;

        public int id
        {
            get
            {
                return orderId;
            }
            set
            {
                this.orderId = value;
            }
        }

        public override string ToString()
        {
            string order = "订单号为" + Convert.ToString(this.id) + " ";
            order = order + this.orderDetails.ToString();
            return order;
        }

        public override bool Equals(object obj)
        {
            return obj is Order order &&
                   orderId == order.orderId &&
                   EqualityComparer<OrderDetails>.Default.Equals(orderDetails, order.orderDetails) &&
                   id == order.id;
        }

        public override int GetHashCode()
        {
            int hashCode = 230357489;
            hashCode = hashCode * -1521134295 + orderId.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer<OrderDetails>.Default.GetHashCode(orderDetails);
            hashCode = hashCode * -1521134295 + id.GetHashCode();
            return hashCode;
        }

        public int CompareTo(Order order)
        {
            return this.id.CompareTo(order.id);
        }
    }
}
